package cn.rubintry.bug.hunting.common.manager

import cn.rubintry.bug.hunting.Constants.USER_DATA
import cn.rubintry.bug.hunting.pojo.UserDataModel
import com.orhanobut.hawk.Hawk


/**
 *
 * @author 卢孙仲
 * 用户登录管理类
 */
class UserManager {

    companion object{
        private var instance: UserManager?= null

        @JvmStatic
        fun getInstance(): UserManager {
            if(null == instance){
                synchronized(UserManager::class.java){
                    if(null == instance){
                        instance = UserManager()
                    }
                }
            }
            return instance!!
        }
    }


    fun save(data: UserDataModel) {
        Hawk.put(USER_DATA , data)
    }


    /**
     * 获取用户信息
     */
    fun getUserData(): UserDataModel? {
        return Hawk.get(USER_DATA) as? UserDataModel
    }


    /**
     * 判断用户是否登录
     */
    fun isLogin(): Boolean {
        return getUserData() != null
    }

    fun logout(): Boolean {
        return Hawk.delete(USER_DATA)
    }
}